﻿@inject IStringLocalizer<Downloads> Localizer
@inject IOptionsMonitor<WebsiteOptions> SiteOptions
@inject ToastService ToastService
@inject DownloadService DownloadService

<Button IsAsync="true" Icon="fa-solid fa-download" Text="@Localizer["DownloadNormalButtonText"]" OnClickWithoutRender="DownloadPhysicalFileAsync"></Button>

@code {

    private async Task DownloadPhysicalFileAsync()
    {
        try
        {
            var filePath = Path.Combine(SiteOptions.CurrentValue.WebRootPath, "favicon.png");
            await using var stream = File.OpenRead(filePath);
            await DownloadService.DownloadFromStreamAsync("favicon.png", stream);
        }
        catch (FileNotFoundException msg)
        {
            await ToastService.Error("下载", msg.Message);
        }
    }
}
